package C;

import java.util.Arrays;
import java.util.Scanner;

public class C48 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),m = sc.nextInt();
        getResult(n,m);


    }
    public static void getResult(int n,int m){
        int line = m,col = (int)Math.ceil((double)n/m);
        String[][] nums = new String[line][col];
//        Arrays.fill(nums,"*");
        for (String[] num : nums) {
            Arrays.fill(num,"*");
        }
        int curL = 0,curC=0;
        int lastLeftCol = -1,lastRightCol = col;
        int lasthighLine = 0,lastLowLine = line;
        int i=1;
        while(i<=n){
            while(curC<lastRightCol && i<=n) {
                nums[curL][curC] = String.valueOf(i);
                curC++;
                i++;
            }
            curC--;
            curL++;
            lastRightCol = curC;
//            lasthighLine = curL;
            while(curL<lastLowLine && i<=n) {
                nums[curL][curC] = String.valueOf(i);
                curL++;
                i++;
            }
            curL--;
            curC--;
            lastLowLine = curL;
            while(curC>lastLeftCol && i<=n) {
                nums[curL][curC] = String.valueOf(i);
                curC--;
                i++;
            }
            curC++;
            curL--;
            lastLeftCol = curC;
            while(curL>lasthighLine && i<=n) {
                nums[curL][curC] = String.valueOf(i);
                curL--;
                i++;
            }
            curL++;
            curC++;
            lasthighLine = curL;
        }
        for (String[] num : nums) {
            System.out.println(Arrays.toString(num));
        }
    }
}
